<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one
  ~ or more contributor license agreements.  See the NOTICE file
  ~ distributed with this work for additional information
  ~ regarding copyright ownership.  The ASF licenses this file
  ~ to you under the Apache License, Version 2.0 (the
  ~ "License"); you may not use this file except in compliance
  ~ with the License.  You may obtain a copy of the License at
  ~
  ~   http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing,
  ~ software distributed under the License is distributed on an
  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~ KIND, either express or implied.  See the License for the
  ~ specific language governing permissions and limitations
  ~ under the License.
-->

<ng-container>
  <nz-tag
    *ngFor="let tag of value; let i = index"
    [nzMode]="mode || (tag.type === 1 ? 'closeable' : 'default')"
    (nzOnClose)="onRemoveTag(tag)"
    [nzColor]="tag.color"
  >
    {{ sliceTagName(tag) }}
  </nz-tag>
  <a (click)="onShowTagsModal()">
    <nz-tag>
      <i nz-icon nzType="plus"></i>
      {{ 'tag.new' | i18n }}
    </nz-tag>
  </a>
</ng-container>

<nz-modal
  [(nzVisible)]="isManageModalVisible"
  [nzTitle]="'tag.bind' | i18n"
  (nzOnCancel)="onManageModalCancel()"
  (nzOnOk)="onManageModalOk()"
  nzMaskClosable="false"
  nzWidth="30%"
  [nzOkLoading]="isManageModalOkLoading"
>
  <div *nzModalContent class="-inner-content">
    <app-toolbar>
      <ng-template #left>
        <app-multi-func-input type="search" [placeholder]="'tag.search' | i18n" [(value)]="tagSearch" (valueChange)="loadTagsTable()" />
      </ng-template>
      <ng-template #right>
        <button nz-button nzType="primary" routerLink="/setting/tags" style="margin-left: 5px">
          <i nz-icon nzType="setting" nzTheme="outline"></i>
          {{ 'tag.setting' | i18n }}
        </button>
      </ng-template>
    </app-toolbar>
    <nz-table #smallTable nzSize="small" [nzData]="tags" [nzPageSize]="8" [nzLoading]="tagTableLoading">
      <thead>
        <tr>
          <th nzAlign="center" nzLeft nzWidth="4%" [(nzChecked)]="tagCheckedAll" (nzCheckedChange)="onAllChecked($event)"></th>
          <th nzAlign="left">{{ 'tag' | i18n }}</th>
        </tr>
      </thead>
      <tbody>
        <tr *ngFor="let data of smallTable.data">
          <td nzAlign="center" nzLeft [nzChecked]="checkedTags.has(data)" (nzCheckedChange)="onItemChecked(data, $event)"></td>
          <td nzAlign="left">
            <nz-tag *ngIf="data.tagValue == undefined || data.tagValue.trim() == ''" [nzColor]="data.color">{{ data.name }}</nz-tag>
            <nz-tag *ngIf="data.tagValue != undefined && data.tagValue.trim() != ''" [nzColor]="data.color">
              {{ data.name + ':' + data.tagValue }}
            </nz-tag>
          </td>
        </tr>
      </tbody>
    </nz-table>
  </div>
</nz-modal>
